﻿@page "/downloads"
@inject IStringLocalizer<Downloads> Localizer

<h3>@Localizer["H1"]</h3>
<h4>@Localizer["H2"]</h4>

<Tips>
    <b>@Localizer["P1"]：</b>
    <div>
        @((@MarkupString)Localizer["P2"].Value)
    </div>
</Tips>

<div class="mb-3">
    @((@MarkupString)Localizer["P4"].Value)：
    <Button Icon="fa-solid fa-download" Text="@Localizer["P5"]" OnClick="@DownloadFileAsync"></Button>
</div>
<div class="mb-2">@((@MarkupString)Localizer["P6"].Value)</div>
<Pre>@Localizer["P7"]</Pre>
<div class="mb-2">@((@MarkupString)Localizer["P8"].Value)</div>
<Pre>private async Task DownloadFileAsync()
{
    using var stream = await GenerateFileAsync();
    await DownloadService.DownloadFromStreamAsync("@Localizer["P9"]", stream);

    static async Task&lt;Stream&gt; GenerateFileAsync()
    {
        var ms = new MemoryStream();
        var writer = new StreamWriter(ms);
        await writer.WriteLineAsync("@Localizer["P10"]");
        await writer.FlushAsync();
        ms.Position = 0;
        return ms;
    }
}</Pre>

@if (!IsWasm)
{
    <DemoBlock Title="@Localizer["P11"]" Introduction="@Localizer["P12"]" Name="Normal">
        <Button IsAsync="true" Icon="fa-solid fa-download" Text="@Localizer["P13"]" OnClickWithoutRender="DownloadPhysicalFileAsync"></Button>
    </DemoBlock>

    <DemoBlock Title="@Localizer["P14"]" Introduction="@Localizer["P15"]" Name="Folder">
        <Button IsAsync="true" Icon="fa-solid fa-download" Text="@Localizer["P16"]" OnClickWithoutRender="DownloadFolderAsync"></Button>
    </DemoBlock>
}

<DemoBlock Title="@Localizer["P17"]" Introduction="@Localizer["P18"]" Name="BigFile">
    <p>@((MarkupString)Localizer["P19"].Value)</p>
    <Button IsAsync="true" Icon="fa-solid fa-download" Text="Download" OnClickWithoutRender="DownloadLargeFileAsync"></Button>
</DemoBlock>

@if(!IsWasm)
{
    <DemoBlock Title="@Localizer["P20"]" Introduction="@Localizer["P21"]" Name="Image">
        <p>@((MarkupString)Localizer["P22"].Value)</p>
        <img src="@TempUrl" style="width: 120px; height: auto;" />
    </DemoBlock>
}
